 import java.awt.Rectangle;

 import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JButton;
 import javax.swing.JPasswordField;
 import javax.swing.JScrollPane;
 import javax.swing.JScrollBar;
 import javax.swing.JComboBox;
 import javax.swing.JTextField;
 import java.awt.event.ActionListener;
 import java.awt.event.ActionEvent;
import java.io.File;
 import java.sql.Date;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;

 import javax.swing.JTable;

 import com.mysql.jdbc.ResultSet;
import com.sun.corba.se.spi.orbutil.fsm.Guard.Result;
/**
 * 
 * this class is open check assignment UI
 *
 */
 public class OpenCheckedAssUI extends JPanel {
	/**
	 * title for the current window  
	 */
 	private JLabel ocsntitle = null;
	/**
	 *  no assignment message 
	 */
 	private JLabel noassnmsg = null;
 	/**
 	 *  back button
 	 */
 	public JButton btnBack = null;
 	/**
 	 * help button
 	 */
 	public JButton btnHelp = null;
	/**
	 * save the current panel for the "back" function 
	 */
 	private JPanel curPanel;
 	private ResultSet res = null;
 	ArrayList<Assignment> l = new ArrayList<Assignment>();
 	private Sub submit;
 	private MyFile file;
 	public JButton btnLogout = null;
 	
 	int i;
 	
 	
 	public OpenCheckedAssUI () {
 		super();
 		emptyinitialize();
 	}

 	public OpenCheckedAssUI(Object msg) {
 		
 		  super();
 		  l = (ArrayList) msg;
 		  initialize();
 	}

 	private void initialize() {
 		curPanel = this;
 		
 		ocsntitle = new JLabel("Open Checked Assignment");
 		ocsntitle.setBounds(160, 28, 180, 14);

 		this.setSize(400, 321);
 		this.setLayout(null);
 		
 		this.add(ocsntitle);
 				
 		int size = l.size();
 		
 		JButton[] b=new JButton[size];
 		JLabel[] lb=new JLabel[size];
 		JLabel[] lb2=new JLabel[size];
 			int x=270, y=60, width=150, height=20, width1=90;
 			int x1=20, x2=110;
 			for ( i=0; i<size ; i++)
 			{
 			//	assn = new Assignment();
 			//	assn = l.get(i);
 				Integer assnum = l.get(i).getAssNumber();
 				SQL s = new SQL (l.get(i).getCourseID(),18);
 				s.accept();
 				Object msg = s.getMsg();
 				System.out.println("this course : " + i + l.get(i).getCourseID()); 
 				//JLabel1
 				lb[i] = new JLabel((String)msg);
 				lb[i].setBounds(x1, y, width, height);
 				curPanel.add(lb[i]);
 				//JLabel2
 				lb2[i] = new JLabel("Assignment No: " +assnum.toString());
 				lb2[i].setBounds(x2, y, width, height);
 				curPanel.add(lb2[i]);
 		
 				//JButton Open
 				b[i] = new JButton("Open");
 				curPanel.add(b[i]);
 				b[i].setBounds(x+80, y, width1, height);
 				b[i].addActionListener(new ActionListener() {
 					public void actionPerformed(ActionEvent arg0) {

 						Date date = new Date(0);
 						date.setYear(2012);
 						date.setMonth(1);
 						date.setDate(19);
 						int x = date.getDate();
 						String date1 = x +"."+date.getMonth()+"."+date.getYear();
						  
 					
 							submit = new Sub (l.get(i-1).getCourseID(),Global.logIn.getUserlogin(),l.get(i-1).getAssNumber(),date1,l.get(i-1).getTeacherID(),file);
 							SQL s1 = new SQL (submit,51);
 							s1.accept();
 							submit = (Sub)s1.getMsg();
 							
 							
 							Save save = new Save(submit.getCheckFile());
 							save.saveFile(submit.getCheckFile());
 							File file = save.getFf(); 
 							
 							CheckSubUI checkSubUI = new CheckSubUI(submit);
 							
 							setVisible(false);
 							System.out.println("Check Assignment");
 							Global.main.setContentPane(checkSubUI);
 							checkSubUI.btnBack.addActionListener(new ActionListener() {   //back from
 								public void actionPerformed(ActionEvent arg0) {
 									Global.main.setContentPane(curPanel);
 									curPanel.setVisible(true);
 								}
 							});
 	
 					}
 				});
 				this.add(b[i],null);
 				this.setVisible(true);
 				//JButton Open
 				y+=30;
 				
 			}
 	
 		btnBack = new JButton("Back");
 		btnBack.setBounds(187, 253, 86, 25);
 		this.add(btnBack,null);
 		this.setVisible(true);
 		
 		btnLogout = new JButton("Logout");        //Logout button
 		btnLogout.setBounds(10, 11, 80, 19);
 		add(btnLogout);
 		btnLogout.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent e) {
 				  LogoutWin logt = new LogoutWin();
 				  System.out.println("user press Logout button");
 			}
 		});
 		this.setVisible(true);
 		
 		btnHelp = new JButton("Help");
 		btnHelp.setBounds(390, 11, 80, 19);
 		btnHelp.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent e) {
 				  HelpWin help = new HelpWin ("Choose an Assignment to see your grade and teacher comments");
 				  System.out.println("user press Help button");
 			}
 		});
 		this.add(btnHelp,null);
 	}
 	
 	private void emptyinitialize() {
 		curPanel = this;

 		noassnmsg = new JLabel("No Checked Assignments For This Student");
 		noassnmsg.setBounds(133, 49, 270, 46);

 		this.setSize(400, 321);
 		this.setLayout(null);
 		this.add(noassnmsg);
 		
 		btnBack = new JButton("Back");
 		btnBack.setBounds(187, 253, 86, 25);
 		this.add(btnBack,null);
 		this.setVisible(true);
		btnHelp = new JButton("Help");
		btnHelp.setBounds(390, 11, 80, 19);
		btnHelp.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				  HelpWin help = new HelpWin ("Choose an Assignment to see your grade and teacher comments");
				  System.out.println("user press Help button");
			}
		});
		this.add(btnHelp,null);
		
		btnLogout = new JButton("Logout");        //Logout button
		btnLogout.setBounds(10, 11, 80, 19);
		add(btnLogout);
		btnLogout.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				  LogoutWin logt = new LogoutWin();
				  System.out.println("user press Logout button");
			}
		});
 	}
 }